package com.zkr.kfkw.conterllor;


import com.zkr.kfkw.model.*;
import com.zkr.kfkw.service.KFKWService;
import com.zkr.util.ResultBuilderVo;
import com.zkr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by lenovo on 2021/1/13.
 */
@RestController
@CrossOrigin
public class KFKWConterllor {

    @Autowired
    private KFKWService kfkwService;


  /**
     * 分页
     * @param
     * @return
     */
    @PostMapping("StorageBin/queryPage")
    public ResultVo queryPage(@RequestBody KFKWSelectVo kfkwSelectVo) {
        return kfkwService.queryPage(kfkwSelectVo);
    }


    /**
     * 添加
     */
    @PostMapping("StorageBin/add")
    public ResultVo add(@RequestBody @Valid List<KFKWAddVo> contentList, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = kfkwService.add(contentList);
        return resultVo;
    }



    /**
     * 修改启用禁用接口
     * @param
     * @param bindingResult
     * @return
     */
    @PostMapping("StorageBin/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid KFKWUpdateStatusVo kfkwUpdateStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfkwService.updateStatus(kfkwUpdateStatusVo);
    }

    /**
     *根据库房id查询库区下的信息
     */
    @GetMapping("StorageBin/queryStorageSection")
    public ResultVo query(Integer id){
        return kfkwService.query(id);

    }


    /**
     * 根据库区编码查询出库位的信息
     */
    @PostMapping("StorageBin/queryStorageBin")
    public ResultVo querykw(@RequestBody KWVo kwVo) {

        return kfkwService.querykw(kwVo);


    }

    /**
     * 修改
     */
    @PostMapping("StorageBin/update")
    public ResultVo update(@RequestBody @Valid KFKWUpdateVo kfkwUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfkwService.update(kfkwUpdateVo);
    }

}








